package com.xiao.common.util;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;

/**
 * @Author xiaoxiaoping
 * @Date 2019/10/31
 */
public class ExcelUtil {
    public Workbook getDataFromExcel(String path){
        FileInputStream fis = null;
        Workbook workbook = null;
        try {
            fis = new FileInputStream(path);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            //2003版本Excel
            workbook = new HSSFWorkbook(fis);
        }catch (Exception e){
            try {
                //2007版本Excel
                workbook = workbook = new XSSFWorkbook(fis);
            } catch (Exception e1){
                e1.printStackTrace();
            }
        }
        return workbook;
    }
}
